<template>
  <view class="index">
    <view class="jtop">
      <view class="status_bar">
        <!-- 这里是状态栏 -->
      </view>
      <view class="jtop_l" @tap="navigateBack">
        <image src="../../static/img/ic_back.png"></image>
      </view>
      <view class="jtop_c">项目合同</view>
      <view class="jtop_r jtop_rl" @click="jshow_pop('jfolder')">
        <image src="../../static/img/doc/ic_add.png"></image>
      </view>
    </view>
    <view class="tophr"></view>
    <!-- <uni-search-bar
      placeholder="搜索"
      @confirm="search"
      class="ss"
    ></uni-search-bar> -->

    <!-- 有合同文件夹 -->
    <view class="doc_bs" v-if="folderList != null && folderList.length > 0">
      <!-- <view class="clb" @tap="to_edit(index,item.id)" v-for="(item, index) in items" :key="item.id">
				{{item.name}}
			</view> -->

      <view class="doc_b " v-for="(item, index) in folderList" :key="item.id">
        <image
          src="../../static/img/doc/ic_folder.png"
          class="doc_bl"
          @tap="to_more(item.id)"
        ></image>
        <view class="doc_b2" @tap="to_more(item.id)">
          <text class="doc_b2t" @tap="to_more(item.id)">{{ item.name }}</text>
        </view>
        <image
          src="../../static/img/doc/ic_ellipsis 3.png"
          class="doc_br"
          @click="jshow_pop('sz', item.id, item.name)"
        ></image>
      </view>

      <!-- <view class="doc_b" @tap="to_more">
				<image src="../../static/img/index/new/ht.png" class="doc_bl"></image>
				<view class="doc_b2">
					<text class="doc_b2t">分包合同</text>
				</view>
				<image src="../../static/img/doc/ic_ellipsis 3.png" class="doc_br"  @click="jshow_pop('sz')"></image>
			</view>
			<view class="doc_b" @tap="to_more">
				<image src="../../static/img/index/new/ht.png" class="doc_bl"></image>
				<view class="doc_b2">
					<text class="doc_b2t">购货合同</text>
				</view>
				<image src="../../static/img/doc/ic_ellipsis 3.png" class="doc_br"  @click="jshow_pop('sz')"></image>
			</view>
			<view class="doc_b" @tap="to_more">
				<image src="../../static/img/index/new/ht.png" class="doc_bl"></image>
				<view class="doc_b2">
					<text class="doc_b2t">人员劳务合同</text>
				</view>
				<image src="../../static/img/doc/ic_ellipsis 3.png" class="doc_br"  @click="jshow_pop('sz')"></image>
			</view>
			 -->
    </view>
    <!-- 无内容 -->
    <view class="no" v-else>
      <view class="no_t">
        <image src="../../static/img/index/2/ic_contract_grey.png"></image>
      </view>
      <view class="no_c">
        暂无合同
      </view>
    </view>

    <!-- 弹出层 -->
    <view :class="[ashowpop ? 'tc' : 'tc hide']">
      <view class="jtop_bj" @click="jshow_pop"></view>

      <view :class="[ashowpop_jtop_rl ? 'tc_fbox' : 'tc_fbox hide']">
        <view class="tc_fboxs">
          <view class="tc_fbox_ic">
            <image src="../../static/img/doc/ic_pic.png"></image>
            <text>上传照片</text>
          </view>
          <view class="tc_fbox_ic">
            <image src="../../static/img/doc/ic_file.png"></image>
            <text>上传文件</text>
          </view>
          <view class="tc_fbox_ic" @click="jshow_pop('jfolder')">
            <image src="../../static/img/doc/ic_folde2r.png"></image>
            <text>新建文件夹</text>
          </view>
        </view>
        <view class="tc_fbox_bt" @click="jshow_pop">
          取消
        </view>
      </view>

      <view :class="[ashowpop_sz ? 'tc_fbox' : 'tc_fbox hide']">
        <view class="tc_list">
          <view class="tc_list_t">
            权限设置
          </view>
          <view class="tc_list" @click="setbj">
            <text class="tc_list1">可编辑</text>
            <text class="tc_listtwo">· 可上传下载，编辑文件夹</text>
            <image src="../../static/img/index/ic_check.png" v-if="!bj"></image>
          </view>
          <view class="tc_list noborder" @click="setbj">
            <text class="tc_list1">仅浏览</text>
            <text class="tc_listtwo">· 仅浏览和下载，不能上传</text>
            <image src="../../static/img/index/ic_check.png" v-if="bj"></image>
          </view>
        </view>
        <view class="tc_fbox_bt" @click="jshow_pop">
          取消
        </view>
      </view>

      <view :class="[ashowpop_jfolder ? 'tc_box' : 'tc_box hide']">
        <view class="tc_boxt">
          新建文件夹
        </view>
        <view class="tc_boxtc">
          请输入文件夹名称
        </view>
        <view class="tc_boxi">
          <input
            type="text"
            placeholder="文件夹名"
            :value="name"
            @input="onKeyInput_o"
            placeholder-style="color:#CCCCCC"
          />
          <image
            src="../../static/img/ic_login_delete.png"
            class="tc_boxi_jdel hide"
          ></image>
        </view>
        <view class="tc_f">
          <view class="tc_fl" @click="jshow_pop">取消</view>
          <view
            class="tc_fr"
            :style="{ opacity: name ? '1' : '.6' }"
            @click="handleCreateFolder"
            >确定</view
          >
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import request from '@/common/request.js';
import { mapState } from 'vuex';

export default {
  data() {
    return {
      repeat_click: true,
      ashowpop: false,
      ashowpop_sz: false,
      ashowpop_jfolder: false,
      ashowpop_jtop_rl: false,
      bj: false,

      nodata: false,
      items: [],
      name: '',
      rootFolder: {}, // 合同文件夹根目录
      currentFolder: {}, // 当前所在的文件夹
      folderList: [], // 当前所在的文件夹下的合同文件夹
    };
  },
  onShow() {
    // this.data_add('88888888');
    this.handleGetRootFloder();
  },
  methods: {
    /**
     * 查询文件夹根目录
     */
    handleGetRootFloder() {
      var param = {
        treeId: (this.projectId = uni.getStorageSync('dqfull_name').id),
        level: 0,
      };
      request({
        url: `/biz/contract-folder/list`,
        method: 'GET',
        data: param,
        success: res => {
          console.log('查询文件夹根目录返回信息:', res);
          if (res.data.success && res.data.data && res.data.data.length > 0) {
            this.rootFolder = res.data.data[0];
            console.log('文件夹根目录:', res);
            // 第一次进入时当前所在的文件夹即为文件夹根目录
            this.currentFolder = this.rootFolder;

            // 获取当前文件夹下的子文件夹
            this.handleGetFolder(this.currentFolder.id, null);
          }
        },
        fail: () => {
          this.repeat_click = true;
          uni.showToast({
            title: '服务器开小差，请稍后~',
            icon: 'none',
          });
          return false;
        },
      });
    },
    /**
     * 获取合同文件夹
     */
    handleGetFolder(parentId, name) {
      this.folderList = [];
      var param = {};
      // 上级文件夹
      if (parentId) {
        param.parentId = parentId;
      }
      // 文件夹名称
      if (name) {
        param.name = name;
      }
      request({
        url: `/biz/contract-folder/list`,
        method: 'GET',
        data: param,
        success: res => {
          console.log('查询当前文件夹下的子文件夹返回信息', res);
          if (res.data.success && res.data.data && res.data.data.length > 0) {
            this.folderList = res.data.data;
            console.log('当前文件夹下的子文件夹列表', this.folderList);
          }
        },
        fail: () => {
          this.repeat_click = true;
          uni.showToast({
            title: '服务器开小差，请稍后~',
            icon: 'none',
          });
          return false;
        },
      });
    },
    /**
     * 创建文件夹
     */
    handleCreateFolder() {
      var param = {
        name: this.name,
        parentId: this.currentFolder.id,
        treeId: (this.projectId = uni.getStorageSync('dqfull_name').id),
        ownerId: (this.projectId = uni.getStorageSync('dqfull_name').id),
      };
      request({
        url: `/biz/contract-folder`,
        data: param,
        method: 'POST',
        success: res => {
          console.log('创建文件夹返回消息:', res);
          if (res.data.success) {
            var that = this;
            that.ashowpop = !this.ashowpop;
            that.ashowpop_jtop_rl = false;
            that.ashowpop_jfolder = false;

            that.handleGetFolder(that.currentFolder.id, null);
            wx.showToast({
              title: '添加成功',
              icon: 'none',
              duration: 1000,
              success: function() {
                setTimeout(function() {}, 1500);
              },
            });

            // uni.navigateBack()
          } else {
            this.repeat_click = true;
            uni.showToast({
              title: res.data.msg,
              icon: 'none',
            });
            this.isLoading = false;
          }
        },
        fail: () => {
          this.repeat_click = true;
          uni.showToast({
            title: '服务器开小差，请稍后~',
            icon: 'none',
          });
          return false;
        },
      });
    },
    data_add(a, b) {
      var jd = {
        page: 1,
        size: 10000,
        treeId: 88888888,
        // level: 1,
      };

      //   if (a == 1) {
      //     jd.content = b;
      //   }
      request({
        url: `/biz/modor-folder/list`,
        method: 'GET',
        data: jd,

        success: res => {
          console.log('文件夹列表', res);
          console.log(res.data.data);

          if (res.data.success == true) {
            if (res.data.data.length > 0) {
              this.items = res.data.data;
              console.log('文件夹列表2', this.items);
              this.nodata = true;
            } else {
              this.items = '';
              this.nodata = false;
            }
          } else {
            // 					this.repeat_click = true;
            //uni.showToast({
            // 	title: res.data.msg,
            // 	icon: 'none'
            // });
          }
        },
        fail: () => {
          this.repeat_click = true;
          uni.showToast({
            title: '服务器开小差，请稍后~',
            icon: 'none',
          });
          return false;
        },
      });
    },
    search(a) {
      this.data_add('88888888', a.value);
    },
    onKeyInput_o: function(event) {
      this.name = event.detail.value;
    },
    jsave() {
      if (!this.repeat_click) {
        return;
      }
      this.repeat_click = false;

      if (!this.name) {
        this.repeat_click = true;
        uni.showToast({
          title: '请输入文件夹名称',
          icon: 'none',
        });
        return;
      }

      request({
        url: `/biz/modor-folder`,
        data: {
          name: this.name,
          ownerId: uni.getStorageSync('user').userInfoResponse.id,
          parentId: 88888888,
          treeId: 88888888,
          type: 2,
        },

        method: 'POST',
        success: openIdRes => {
          console.log(openIdRes);
          if (openIdRes.data.success == true) {
            var that = this;
            that.ashowpop = !this.ashowpop;
            that.ashowpop_jtop_rl = false;
            that.ashowpop_jfolder = false;

            that.data_add('-1');
            wx.showToast({
              title: '添加成功',
              icon: 'none',
              duration: 1000,
              success: function() {
                setTimeout(function() {}, 1500);
              },
            });

            // uni.navigateBack()
          } else {
            this.repeat_click = true;
            uni.showToast({
              title: openIdRes.data.msg,
              icon: 'none',
            });
            this.isLoading = false;
          }
        },
        fail: () => {
          this.repeat_click = true;
          uni.showToast({
            title: '服务器开小差，请稍后~',
            icon: 'none',
          });
          return false;
        },
      });
    },
    navigateBack() {
      uni.navigateBack();
    },
    to_more(folderId) {
      uni.navigateTo({
        url: '../main/agreement_more?folderId=' + folderId,
      });
    },
    // 跳转
    to_gis() {
      uni.navigateTo({
        url: '../doc/doc_gis',
      });
    },
    to_pan() {
      uni.navigateTo({
        url: '../doc/doc_pan',
      });
    },

    // 跳转
    to_about() {
      uni.navigateTo({
        url: '../doc/doc_details',
      });
    },

    jshow_pop(a) {
      this.ashowpop = !this.ashowpop;
      this.ashowpop_jtop_rl = false;
      this.ashowpop_jfolder = false;

      console.log(a);
      if (a == 'jtop_rl') {
        this.ashowpop_jtop_rl = true;
      }
      if (a == 'jfolder') {
        this.ashowpop = true;
        this.ashowpop_jfolder = true;
      }
      if (a == 'sz') {
        this.ashowpop_sz = true;
      }
    },
    setbj() {
      this.bj = !this.bj;
    },
  },
};
</script>

<style>
.tophr {
  width: 100%;
  height: 88rpx;
}

.uni-searchbar {
  box-shadow: none;
}

.no {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  margin: 400rpx 0 0;
}

.no_t {
  width: 200rpx;
  height: 200rpx;
  display: block;
  float: left;
  margin: 0 275rpx;
  background: #ffffff;
  border-radius: 200rpx;
}

.no_t image {
  width: 140rpx;
  height: 140rpx;
  display: block;
  float: left;
  margin: 30rpx;
}

.no_c {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  margin: 30rpx 0 50rpx;
  color: #666666;
  font-size: 32rpx;
  line-height: 40rpx;
  text-align: center;
}

.no_f {
  width: 460rpx;
  height: 94rpx;
  line-height: 94rpx;
  background: #256aff;
  border-radius: 10rpx;
  display: block;
  float: left;
  margin: 0 145rpx;
  color: #ffffff;
  font-size: 36rpx;
  text-align: center;
}

.no_f:active {
  background: linear-gradient(
      0deg,
      rgba(0, 0, 0, 0.199437),
      rgba(0, 0, 0, 0.199437)
    ),
    #256aff;
}

.tc {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10000;
  display: block;
}

.jtop_bj {
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10000;
}

.tc_box {
  width: 540rpx;
  height: auto;
  background: #ffffff;
  border-radius: 14rpx;
  margin: 460rpx 105rpx 0;
  position: relative;
  z-index: 10001;
  overflow: hidden;
}

.tc_boxt {
  width: 100%;
  height: 44rpx;
  font-size: 36rpx;
  line-height: 44rpx;
  display: block;
  float: left;
  text-align: center;
  margin: 40rpx 0 20rpx;
  color: #000000;
}

.tc_boxtc {
  width: 100%;
  height: 36rpx;
  font-size: 28rpx;
  line-height: 36rpx;
  display: block;
  float: left;
  text-align: center;
  margin: 0rpx 0 30rpx;
  color: #666666;
}

.tc_boxi {
  width: 460rpx;
  height: 88rpx;
  background: #ffffff;
  border-radius: 8rpx;
  border: 1px solid #dddddd;
  display: block;
  float: left;
  margin: 0rpx 40rpx 22rpx 40rpx;
}

.tc_boxi input {
  width: 70%;
  height: 48rpx;
  margin: 20rpx 5%;
  font-size: 32rpx;
  color: #000000;
  float: left;
}

.tc_boxi image {
  width: 36rpx;
  height: 36rpx;
  display: block;
  float: right;
  margin: 26rpx 20rpx 0rpx 0;
}

.tc_f {
  width: 100%;
  height: 100rpx;
  display: block;
  float: left;
  border-top: 1px solid #dcdee3;
  margin: 20rpx 0 0;
}

.tc_fl {
  width: 269rpx;
  height: 100rpx;
  line-height: 100rpx;
  text-align: center;
  font-size: 36rpx;
  color: #256aff;
  display: block;
  float: left;
  border-right: 1px solid #dcdee3;
}

.tc_fr {
  width: 269rpx;
  height: 100rpx;
  line-height: 100rpx;
  text-align: center;
  font-size: 36rpx;
  color: #256aff;
  display: block;
  float: left;
}

.tc_fr2 {
  width: 269rpx;
  height: 100rpx;
  line-height: 100rpx;
  text-align: center;
  font-size: 36rpx;
  color: #eb5342;
  display: block;
  float: left;
}

.tc_fbox {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  background: #ffffff;
  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 10001;
}

.tc_fboxs {
  width: 100%;
  height: auto;
  display: block;
  float: left;
}

.tc_fbox_ic {
  width: 33.3333%;
  display: block;
  float: left;
  text-align: center;
  font-size: 28rpx;
  color: #666666;
}

.tc_fbox_ic image {
  width: 72rpx;
  height: 72rpx;
  display: block;
  float: none;
  margin: 60rpx auto 24rpx;
}

.tc_fbox_ic text {
  width: 100%;
  height: auto;
  display: block;
  float: none;
  margin: 0 auto 64rpx;
}

.tc_fbox_bt {
  width: 100%;
  height: 90rpx;
  line-height: 90rpx;
  display: block;
  float: left;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
  border-top: 20rpx solid #f2f2f2;
}

.tc_list {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  background: #ffffff;
}

.tc_list_t {
  width: 100%;
  height: 80rpx;
  display: block;
  float: left;
  background: #ffffff;
  font-size: 24rpx;
  color: #999999;
  line-height: 80rpx;
  margin: 0rpx 0;
  border-bottom: 1px solid #dddddd;
  text-align: center;
}

.tc_list {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  border-bottom: 1px solid #dddddd;
}

.tc_list1 {
  width: auto;
  height: auto;
  display: block;
  float: left;
  font-size: 36rpx;
  color: #000000;
  line-height: 44rpx;
  margin: 34rpx 28rpx 38rpx 30rpx;
}

.tc_listtwo {
  width: auto;
  height: auto;
  display: block;
  float: left;
  font-size: 28rpx;
  color: #999999;
  line-height: 36rpx;
  margin: 42rpx 0rpx 0rpx 0rpx;
}

.tc_list image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: right;
  margin: 36rpx 30rpx 0 0;
}

.doc_t {
  width: 690rpx;
  height: 32rpx;
  font-size: 24rpx;
  line-height: 32rpx;
  color: #999999;
  background: rgb(242, 242, 242);
  padding: 14rpx 30rpx;
  display: block;
  float: left;
}

.doc_bs {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  background: #ffffff;
  border-bottom: 1px solid #dddddd;
  border-left: 0;
  border-right: 0;
}

.doc_b {
  width: 720rpx;
  height: auto;
  display: block;
  float: left;
  background: #ffffff;
  border-bottom: 1px solid #dddddd;
  margin: 0 0 0 30rpx;
}

.doc_bl {
  width: 64rpx;
  height: 64rpx;
  display: block;
  float: left;
  margin: 26rpx 20rpx 22rpx 0;
}

.doc_bt {
  width: auto;
  height: 42rpx;
  line-height: 42rpx;
  font-size: 34rpx;
  display: block;
  float: left;
  color: #000000;
  margin: 37rpx 0 0 0;
}

.doc_br {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: right;
  margin: 32rpx 30rpx 32rpx 0;
}

.doc_b2 {
  width: 450rpx;
  height: auto;
  display: block;
  float: left;
}

.doc_b2t {
  width: 450rpx;
  height: 42rpx;
  font-size: 34rpx;
  line-height: 42rpx;
  color: #000000;
  margin: 34rpx 0 4rpx;
  display: block;
  float: left;
}

.doc_b2f {
  width: 450rpx;
  height: 32rpx;
  font-size: 24rpx;
  line-height: 32rpx;
  color: #999999;
  margin: 0rpx 0 rpx;
  display: block;
  float: left;
}

.doc_b:last-child {
  border: 0;
}

.index {
  background: #ffffff;
  width: 100%;
  height: auto;
}

.jtop {
  width: 100%;
  height: 88rpx;
  background: #ffffff;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  box-shadow: inset 0px -1px 0px #dddddd;
}

.jtop_l {
  width: auto;
  height: 88rpx;
  display: block;
  float: left;
  font-size: 32rpx;
  color: #000000;
  line-height: 88rpx;
  margin: 0 0 0 30rpx;
}

.jtop_l image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
  margin: 20rpx 0 20rpx 0;
}

.jtop_lt {
  margin: 0 0 0 10rpx;
}

.jtop_r {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: right;
  margin: 20rpx 20rpx 0 0;
}

.jtop_rl {
  margin: 20rpx 30rpx 0 0;
}

.jtop_r image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
}

.jtop_c {
  width: 70%;
  height: 48rpx;
  line-height: 48rpx;
  display: block;
  float: left;
  position: fixed;
  top: 20rpx;
  left: 15%;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
}

.jtop_c image {
  width: 36rpx;
  height: 36rpx;
  display: inline-block;
  float: none;
  margin-bottom: -5rpx;
  margin-left: 5rpx;
}

.jtop_b {
  width: 100%;
  height: auto;
  background: #ffffff;
  position: fixed;
  top: 88rpx;
  left: 0;
  z-index: 1001;
}
</style>
